<template>
	<view class="body">
		<!-- 操作菜单 -->
		<paper-left-popup 
		:show="show"
		@hide="hidepopup"
		@addfriend="addfriend"
		@clear="clear"></paper-left-popup>
		<!-- 小纸条列表 -->
		<block v-for="(item,index) in list" :key="index">
			<paper-list :item="item" :index="index"></paper-list>
		</block>
		
		<!-- 上拉加载 -->
		<load-more :loadtext="loadtext"></load-more>
	</view>
</template>

<script>
	import paperList from "../../components/paper/paper-list.vue"
	import loadMore from "../../components/common/load-more.vue"
	import paperLeftPopup from "../../components/paper/paper-left-popup.vue"
	export default {
		components:{
			paperList,
			loadMore,
			paperLeftPopup
		},
		data() {
			return {
				show:false,
				loadtext:"上拉加载更多",
				list:[
					{
						userpic:"../../static/img/daofeng.jpg",
						username:"泰隆",
						time:"10:21",
						data:"我是男刀",
						noreadnum:0
					},
					{
						userpic:"../../static/img/ruiwen.jpg",
						username:"锐雯",
						time:"6:00",
						data:"我是锐雯",
						noreadnum:2
					},
					{
						userpic:"../../static/img/xiazi.jpg",
						username:"盲僧",
						time:"9:00",
						data:"我是瞎纸",
						noreadnum:3
					},
					{
						userpic:"../../static/img/timo.jpg",
						username:"提莫",
						time:"22:00",
						data:"我是提莫",
						noreadnum:0
					},
					{
						userpic:"../../static/img/daofeng.jpg",
						username:"泰隆",
						time:"10:21",
						data:"我是男刀",
						noreadnum:0
					},
					{
						userpic:"../../static/img/ruiwen.jpg",
						username:"锐雯",
						time:"6:00",
						data:"我是锐雯",
						noreadnum:2
					},
					{
						userpic:"../../static/img/xiazi.jpg",
						username:"盲僧",
						time:"9:00",
						data:"我是瞎纸",
						noreadnum:3
					},
					{
						userpic:"../../static/img/timo.jpg",
						username:"提莫",
						time:"22:00",
						data:"我是提莫",
						noreadnum:0
					},
					{
						userpic:"../../static/img/daofeng.jpg",
						username:"泰隆",
						time:"10:21",
						data:"我是男刀",
						noreadnum:0
					},
					{
						userpic:"../../static/img/ruiwen.jpg",
						username:"锐雯",
						time:"6:00",
						data:"我是锐雯",
						noreadnum:2
					},
					{
						userpic:"../../static/img/xiazi.jpg",
						username:"盲僧",
						time:"9:00",
						data:"我是瞎纸",
						noreadnum:3
					},
					{
						userpic:"../../static/img/timo.jpg",
						username:"提莫",
						time:"22:00",
						data:"我是提莫",
						noreadnum:0
					},
					{
						userpic:"../../static/img/daofeng.jpg",
						username:"泰隆",
						time:"10:21",
						data:"我是男刀",
						noreadnum:0
					},
					{
						userpic:"../../static/img/ruiwen.jpg",
						username:"锐雯",
						time:"6:00",
						data:"我是锐雯",
						noreadnum:2
					},
					{
						userpic:"../../static/img/xiazi.jpg",
						username:"盲僧",
						time:"9:00",
						data:"我是瞎纸",
						noreadnum:3
					},
					{
						userpic:"../../static/img/timo.jpg",
						username:"提莫",
						time:"22:00",
						data:"我是提莫",
						noreadnum:0
					},
				]
			}
		},
		onPullDownRefresh(){
			this.getdata()
		},
		onReachBottom(){
			this.loadmore()
		},
		//导航按钮
		onNavigationBarButtonTap(e){
			switch(e.index) {
				case 0:
				uni.navigateTo({
					url:"../user-list/user-list"
				});
				break;
				case 1:
				this.showpopup()
				break;
			}
		},
		methods: {
			//操作菜单
			addfriend(){
				// 加好友
				this.hidepopup()
			},
			clear(){
				//清除
				this.hidepopup()
			},
			hidepopup(){
				this.show = false
			},
			showpopup(){
				this.show = true
			},
			loadmore(){
				if(this.loadtext!=='上拉加载更多'){return;}
				//修改状态
				this.loadtext="加载中...";
				//获取数据
				setTimeout(()=>{
					//获取完成
					let obj = {
						userpic:"../../static/img/timo.jpg",
						username:"提莫",
						time:"22:00",
						data:"我是提莫",
						noreadnum:1
					};
					this.list.push(obj)
					this.loadtext='上拉加载更多'
				},1000);
				//this.loadtext = "没有更多数据了"
			},
			getdata(){
				setTimeout(()=>{
					let arr = [
						    {
								userpic:"../../static/img/yasuo.jpg",
								username:"亚索",
								time:"10:21",
								data:"我是亚索",
								noreadnum:0
							},
							{
								userpic:"../../static/img/pika.jpg",
								username:"皮卡丘",
								time:"6:00",
								data:"我是皮卡丘",
								noreadnum:2
							},
							{
								userpic:"../../static/img/yuanshen.jpg",
								username:"原神",
								time:"9:00",
								data:"我是瞎纸",
								noreadnum:3
							},
							{
								userpic:"../../static/img/timo.jpg",
								username:"提莫",
								time:"22:00",
								data:"我是提莫",
								noreadnum:0
							}
					];
					this.list = arr;
					uni.stopPullDownRefresh();
				},1000)
			}
		}
	}
</script>

<style>
.body {
	padding: 0 20upx;
}
</style>
